home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / swtools / libdmalloc / test5.c < prev   
Encoding:
C/C++ Source or Header  |  1994-08-02  |  1.8 KB  |  74 lines

  1. /*
  2.  * Copyright (C) 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. /*
  18.     Program to test whether malloc is mp-safe.
  19.     sproc, and both parent and child do 1000 mallocs.
  20.  */
  21. #include <malloc.h>
  22. #include <sys/types.h>
  23. #include <sys/prctl.h>
  24. #include <stdio.h>
  25. #include <assert.h>
  26.  
  27.  
  28. malloc_init_function()
  29. {
  30.     extern int malloc_stacktrace_get_depth;
  31.     malloc_stacktrace_get_depth = -1;
  32. }
  33.  
  34. void child_entry(void *arg)
  35. {
  36.     int i;
  37.     for (i = 0; i < 10000; ++i) {
  38.     assert(malloc(3));
  39.     free(malloc(3));
  40.     }
  41.     printf("====== Child: done with 10000 mallocs ------\n");
  42.  
  43.     while (1) {
  44.     /* printf("====== Child: sleeping for 10 seconds ======\n"); */
  45.     sleep(3);
  46.     /* printf("====== Child: calling malloc 5 ======\n"); */
  47.     malloc(5);
  48.     }
  49. }
  50.  
  51. main(int argc, char **argv)
  52. {
  53.     int i;
  54.     malloc(7);
  55.  
  56.     printf("sprocing.\n");
  57.  
  58.     if (sproc(child_entry, PR_SALL, NULL) == -1)
  59.     perror("sproc");
  60.  
  61.     for (i = 0; i < 10000; ++i) {
  62.     assert(malloc(3));
  63.     free(malloc(3));
  64.     }
  65.     printf("------ Parent: done with 10000 mallocs ------\n");
  66.  
  67.     for (i = 0; ; ++i) {
  68.     sleep(1);
  69.     malloc_info(1, -1);
  70.     if (i == 0)
  71.         malloc_reset();
  72.     }
  73. }
  74.